import React, { Component } from 'react';
import './index.css';
export default class Footer extends Component {
  // 全选
  checkAllTodo = (e) => {
    this.props.checkAllTodo(e.target.checked);
  };

  // 清除已完成任务
  clearAllDone = () => {
    this.props.clearAllDone();
  };
  render() {
    const { todos } = this.props;
    // 已完成
    const doneCount = todos.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0);
    // 全部
    const total = todos.length;

    return (
      <div className='todo-footer'>
        <label>
          <input
            type='checkbox'
            onChange={this.checkAllTodo}
            checked={doneCount === total && total !== 0 ? true : false}
          />
          <span>已完成{doneCount}</span>
          <span>/</span>
          <span>全部{total}</span>
        </label>
        <button onClick={this.clearAllDone} className='btn btn-clear'>
          清除已完成任务
        </button>
      </div>
    );
  }
}
